<script>
import { requestApi } from '@/requset/api'
import { config, column } from './formConfig.js'
import BasicManage from '@/components/basic/BasicManage.vue'
import { deepClone } from '@/plugins/clone'
export default {
    extends: BasicManage,
    data() {
        return {
            table_title: '分工厂',
            url: 'backstage',
            baseForm: {
                name: '',
                parent: null,
                type: 'factory',
                factory_img: null,
            },
            queryForm: {
                size: 20,
                page: 1,
                type: 'factory',
            },
            confirmText: '确认删除此条数据?本次操作会清空该区域下所有测点在数据库中的表和数据',
        }
    },
    methods: {
        from(data) {
            data.parent = data.company_id
            try {
                data.address = JSON.parse(data.province)
            } catch (error) {}
            return data
        },
        getOption() {
            requestApi('post', this.url + `/getlist`, { type: 'company', page: 1 }).then((res) => {
                this.dialog.config[0].options = res.data.data
            })
        },
        cityList() {
            requestApi('get', 'backstage/city/area/list').then((res) => {
                if (res.data.success) {
                    this.dialog.config[2].options = res.data.data
                } else {
                    this.dialog.config[2].options = []
                }
            })
        },
        handleEdit(val) {
            this.dialog.title = '编辑' + this.table_title

            this.dialog.form = this.from(deepClone(val))

            this.$refs.zyform.openDialog('change')
        },
    },
    created() {
        this.dialog.labelWidth = '120px'
        column[column.length - 1].buttons = [
            {
                text: '编辑',
                click: (val) => {
                    this.handleEdit(val)
                },
                icon: 'el-icon-edit',
            },
            {
                text: '删除',
                click: (val) => {
                    this.delete(val)
                },
                icon: 'el-icon-delete',
            },
        ]
        column[column.length - 1].if = this.operate
        this.dialog.config = config
        this.tableColumn = column
        this.getlist()
        this.getOption()
        this.cityList()
    },
}
</script>
